<template>
  <div>
    <div>
        <divider>请登陆</divider>
        <group label-width="4.5em" label-margin-right="2em" label-align="right">
            <x-input   type="text" placeholder="登陆名" v-model="form.loginName"></x-input>
            <x-input   type="password" placeholder="密码" v-model="form.password"></x-input>
        </group>
        <x-button type="primary" action-type="button" @click.native="login()">登陆</x-button>
    </div>
  </div>
</template>
<script>
import { Group, XInput, XButton, Divider,Loading } from "vux";
import { debug } from 'util';

export default {
  components: {
    Group,
    XInput,
    XButton,
    Divider,
    Loading
  },
  data(){
    return {
        form:{
          loginName:'',
          password:''
        }
    }
  },
  methods: {
    login(){
      this.$http.post("/work/api/login",this.form).then(res=>{
      //全局用户信息保存
      this.$store.commit("updateUserInfo",{userInfo:res.data.data})
      if(this.$route.query.redirect){
          //登陆后回到当前页
          location.href = this.$route.query.redirect;
      }else{
        //否者回到上一页
        this.$router.go(-1)
      }
    })
  }

  },

};
</script>
